package com.songtech.alert.controller;


import com.songtech.alert.service.AlertService;
import com.songtech.base.common.BaseConstant;
import com.songtech.base.common.JsonResult;
import com.songtech.login.model.SysPosUser;
import com.songtech.server.entry.AlertEntry;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;


@Controller
@RequestMapping("/alert")
public class AlertController {

    private Logger logger = LoggerFactory.getLogger(AlertController.class);

    @Autowired
    private AlertService alertService;


    @RequestMapping("/warning")
    @ResponseBody
    public JsonResult selectAll(HttpSession session, HttpServletRequest request){
       // String imei="123";
        SysPosUser user=(SysPosUser)session.getAttribute("loginUser");
        List<AlertEntry> list = null;
        try {
            list = alertService.getAlertInfo(user.getImei());
        } catch (Exception e) {
            logger.error("查询告警异常信息:"+e.getMessage(),e);
            return new JsonResult(list, BaseConstant.FAIL_CODE, BaseConstant.FAIL);
        }
        return new JsonResult(list, BaseConstant.SUCCESS_CODE, BaseConstant.SUCCESS);
    }

}
